package com.ruoyi.userr.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.userr.domain.VipOrders;
import com.ruoyi.userr.service.IVipOrdersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员订单（记录支付和有效期）Controller
 *
 * @author sr
 * @date 2025-08-17
 */
@RestController
@RequestMapping("/userr/orders")
public class VipOrdersController extends BaseController
{
    @Autowired
    private IVipOrdersService vipOrdersService;

    /**
     * 查询会员订单（记录支付和有效期）列表
     */
    //@PreAuthorize("@ss.hasPermi('userr:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(VipOrders vipOrders)
    {
        startPage();
        List<VipOrders> list = vipOrdersService.selectVipOrdersList(vipOrders);
        return getDataTable(list);
    }

    /**
     * 导出会员订单（记录支付和有效期）列表
     */
    @PreAuthorize("@ss.hasPermi('userr:orders:export')")
    @Log(title = "会员订单（记录支付和有效期）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VipOrders vipOrders)
    {
        List<VipOrders> list = vipOrdersService.selectVipOrdersList(vipOrders);
        ExcelUtil<VipOrders> util = new ExcelUtil<VipOrders>(VipOrders.class);
        util.exportExcel(response, list, "会员订单（记录支付和有效期）数据");
    }

    /**
     * 获取会员订单（记录支付和有效期）详细信息
     */
    @PreAuthorize("@ss.hasPermi('userr:orders:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(vipOrdersService.selectVipOrdersById(id));
    }

    /**
     * 新增会员订单（记录支付和有效期）
     */
   // @PreAuthorize("@ss.hasPermi('userr:orders:add')")
    @Log(title = "会员订单（记录支付和有效期）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VipOrders vipOrders)
    {
        return toAjax(vipOrdersService.insertVipOrders(vipOrders));
    }

    /**
     * 修改会员订单（记录支付和有效期）
     */
    @PreAuthorize("@ss.hasPermi('userr:orders:edit')")
    @Log(title = "会员订单（记录支付和有效期）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VipOrders vipOrders)
    {
        return toAjax(vipOrdersService.updateVipOrders(vipOrders));
    }

    /**
     * 删除会员订单（记录支付和有效期）
     */
    @PreAuthorize("@ss.hasPermi('userr:orders:remove')")
    @Log(title = "会员订单（记录支付和有效期）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(vipOrdersService.deleteVipOrdersByIds(ids));
    }
}
